<?php

namespace App\Http\Controllers\Pay;

use Illuminate\Http\Request;
use Alipay\EasySDK\Kernel\Config;
use Alipay\EasySDK\Kernel\Factory;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class AlipayController extends Controller
{
    // 异步&&同步通知页面，放一起了
    public function postRecharge(Request $request)
    {
        try {
            $data = $request->all();
            Storage::disk('log')->prepend('alipay.log', json_encode($data) . date('Y-m-d H:i:s'));
            Factory::setOptions($this->getOptions());
            $r = Factory::payment()->common()->verifyNotify($data);
            // 验证成功
            if ($r && $data['trade_status'] == 'TRADE_SUCCESS') {
                // 统一回调处理方法
            }
            echo "success";
        } catch (\Throwable $th) {
            echo "fail";
        }
    }
}
